<template>
  <el-select
    ref="select"
    v-model="content"
    filterable
    clearable
    placeholder="请输入名称搜索"
    :loading="loading"
    v-bind="$attrs"
    @change="change"
  >
    <el-option
      v-for="item in list"
      :key="item.loginNum"
      :label="item.loginNum"
      :value="item.loginNum"
    >
      <!-- 自定义选择显示值 -->
      <template>
        <div class="itemBox">
          <span>{{ item.loginNum }} </span>
          <!-- <span>{{ item.loginNum }}</span> -->
        </div>
      </template>
    </el-option>
  </el-select>
</template>

<script>
/*
选择用户-单选

<selectUser v-model.trim="model.loginNum" />

import selectUser from '@/components/xm/selectUser/selectUser'

*/
import { api_getMemberUser } from '@/api/user'

export default {
  components: {},
  model: {
    prop: 'loginNum',
    event: 'change'
  },
  props: {
    // 搜索名称
    loginNum: {
      type: String,
      default: ''
    }
  },
  data() {
    return {
      loading: false,
      list: []
    }
  },
  computed: {
    content: {
      get() {
        return this.loginNum
      },
      set(val) {
        this.$emit('change', val)
      }
    }
  },
  mounted() {
    console.log('mounted')
    this.getList('')
  },
  methods: {
    // 获取列表
    getList(loginNum) {
      this.loading = true
      api_getMemberUser({ loginNum, pageSize: 200, pageNum: 1 }).then(res => {
        if (res.code === 1) {
          this.list = res.data
        }
      }).finally(() => {
        this.loading = false
      })
    },
    change(val) {
      // const obj = this.list.find(v => v.oldFacilitiyNo === val) || {}
      // this.$emit('change', obj)
    }
  }
}

</script>
<style scoped lang='scss'>
.el-select{
  width:100%;
}
.itemBox{
  display:flex;
  justify-content:space-between;
}
</style>
